<?php
require_once(dirname(__FILE__) . '/config/index.php');

class TestOfString extends UnitTestCase {

	protected $str;

	public function __construct() {
		$this->str = new Nina_String('haddock');
	}

	public function testGet() {
		$this->assertEqual($this->str->get(), 'haddock');
	}

	public function testTrim() {
		$str = new Nina_String(' haddock ');
		$this->assertEqual($str->trim(), 'haddock');
	}
	
	public function testLength() {
		$this->assertEqual($this->str->length(), 7);
	}
	
	public function testUpcase() {
		$this->assertEqual($this->str->upcase(), 'HADDOCK');
	}
	
	public function testDowncase() {
		$str = new Nina_String('HaDDocK');
		$this->assertEqual($str->downcase(), 'haddock');
	}
	
	public function testCapitalise() {
		$this->assertEqual($this->str->capitalise(), 'Haddock');
	}
	
	public function testMd5() {
		$this->assertEqual($this->str->md5(), '78375e1e2573151f013c05cc2825bc45');
	}
	
	public function testWordcount() {
		$str = new Nina_String('HaDDocK');
		$this->assertEqual($this->str->wordcount(), 1);
	}
	
	public function testSprintf() {
		$str = new Nina_String('The %s contains %d monkeys');
		$this->assertEqual($str->sprintf('hovercraft', 18), 'The hovercraft contains 18 monkeys');
	}

	public function testContains() {
		$str = new Nina_String('HaDDocK');
		$this->assertTrue($str->contains('d'));
		$this->assertFalse($str->contains('d', true));
		$this->assertTrue($str->contains('H', true));
		$this->assertFalse($str->contains('j'));
	}

	public function testPosition() {
		$str = new Nina_String('HaDDocK');
		$this->assertEqual($str->position('d'), 2);
		$this->assertFalse($str->position('d', true));
		$this->assertEqual($str->position('H', true), 0);
		$this->assertFalse($str->position('j'));
	}

	public function testSubstring() {
		$this->assertEqual($this->str->substring(2, 2), 'dd');
		$this->assertEqual($this->str->substring(-2, 2), 'ck');
	}

	public function testReplace() {
		$this->assertEqual($this->str->replace('dock', ' a nice day'), 'had a nice day');
	}
	
	public function testShorten() {
		$this->assertEqual($this->str->shorten(3), 'had...');
		$this->assertEqual($this->str->shorten(30), 'haddock');
	}
	
	public function testSanitise() {
		$str = new Nina_String(" \'good & morning\' ");
		$this->assertEqual($str->sanitise(), "'good &amp; morning'");
		$this->assertEqual(Nina_String::doSanitise(" \'good & morning\' "), "'good &amp; morning'");
	}
	
	public function testCamelise() {
		$str = new Nina_String('good_morning_to_you');
		$this->assertEqual($str->camelise(), 'GoodMorningToYou');
		$this->assertEqual(Nina_String::doCamelise('good_morning_to_you'), 'GoodMorningToYou');
	}
	
	public function testUnderscore() {
		$str = new Nina_String('GoodMorningToYou');
		$this->assertEqual($str->underscore(), 'good_morning_to_you');
		$this->assertEqual(Nina_String::doUnderscore('GoodMorningToYou'), 'good_morning_to_you');
	}
}
